/**
 * 考勤详细信息列表attendDetailList.js
 * 版本号： v1.0.0
 */
$(function(){

    //设置时间
    if( $("#startTime_").datetimebox('getValue') == ''){
        var curr_time = new Date();
        var currentYear = curr_time.getFullYear();
        var currentMonth = curr_time.getMonth()+1;

        $("#startTime_").datetimebox("setValue", currentYear + "-" + currentMonth + "-" + "01 00:00:00");
        $("#endTime_").datetimebox("setValue", getFirstDay(curr_time) + " 23:59:59");
    }


    $("#attendDetail_dataList").datagrid({
        fitColumns: true,
        fit:true,
        method: "POST",
        rownumbers: true,
        singleSelect:true,
        border: false,
        striped:true,
        url: CONTEXT_PATH + '/attendDetail/attendDetailList.do',
        idField: 'person.cardNo',
        queryParams:{idCard:$('#idCard_').val(),projectId:$('#projectId_').val(),startTime:$('#startTime_').datebox('getValue'), endTime:$('#endTime_').datebox('getValue')},
        columns: [
            [
                {field: 'projectId', title: '项目id', width: 180, fixed: true,hidden:true},
                {field: 'projectName', title: '所属项目', width: 180, fixed: true},
                {field: 'person', title: '姓名', width: 80, fixed: true,
                    formatter:function(val){
                        if(val){
                            return val.name;
                        }
                    }
                },
                {field: '_idCard', title: '身份证号', width: 180, fixed: true,
                    formatter:function(val,row,index){
                        return row.person.idCard;
                    }
                },
                {field: '_groupType', title: '班组', width: 80, fixed: true,
                    formatter:function(val,row,index){
                        return row.person.group.name;
                    }
                },
                {field: 'attendDate', title: '考勤日期', width: 100, fixed: true},
                {field: 'timeResult', title: '进出场时间', width: 180,fixed: true,
                    formatter:function (value) {
                        if(value){
                           return '<a href="#" style="display:block;height: 30px;width:100%;line-height: 2.5;" onMouseOver="toolTip(this,event,\''+value+'\')" onMouseOut="toolHide()">'+value+'</a>';
                        }

                    }

                },
                {field: 'attendLength', title: '工时', width: 100}
            ]
        ],
        onLoadSuccess: function (data) {
            window.parent.loadListCompanly();
        }
    });

    //查询按钮绑定事件
    $('#timeSerach').bind('click', function(){
        var startTime = $("#startTime_").datebox("getValue");
        var endTime = $("#endTime_").datebox("getValue");
        var idCard = $("#idCard_").val();
        var projectId = $("#projectId_").val();
        $("#attendDetail_dataList").datagrid("reload",{idCard:idCard,projectId:projectId,startTime:startTime,endTime:endTime});
    });
});

/**
 * 鼠标移入弹出弹框
 * @param t 指当前对象，即超链接
 * @param e event事件
 * @param timeData 要显示的内容
 */
function toolTip(t,e,timeData){
    if(timeData){
        if( $('#tooltip').length == 0){
            var timeArr = timeData.split(",");
            var timeResult = "";
            for(var i=0;i<timeArr.length;i++){
                timeResult = timeResult + timeArr[i]+"\n";
            }
            var topHeight = e.pageY;
            var bodyHeight = $('#easyuiLayoutId').height();
            var tooltipHtml = "<div id='tooltip' class='tooltip' onClick='removeTooltip(this)'>" +
                "<p style='color: #0c80d7'>提示：点击本框中任意位置则移除！</p>" +
                "<textarea style='height: 100px;width: 200px'>"+timeResult+"</textarea>" +
                "</div>";
            $(t).append(tooltipHtml); //添加到页面中
            var tipHeight = $('#tooltip').height();
            var tipTotal = topHeight + tipHeight;
            if(tipTotal > bodyHeight){
                topHeight =  topHeight - tipHeight;
            }else{
                topHeight =  topHeight - 40;
            }
            $("#tooltip").css({
                "top": topHeight + "px",
                "left": (e.pageX-20) + "px"
            }).show("fast"); //设置提示框的坐标，并显示
        }else{

        }
    }
}

/**
 * 点击提示框移除本框
 */
function removeTooltip() {
    $("#tooltip").remove()
}



